package view.component.weapon
{
	import enums.ColorLib;
	import enums.main.UISize;
	
	import feathers.display.Scale3Image;
	
	import starling.display.Quad;
	import starling.display.Sprite;
	import starling.utils.Color;
	
	import util.FG2FUGenerator;
	
	
	/**
	 * 斩味容器
	 * @author £iang
	 * 
	 */	
	public class SharpContainer extends Sprite
	{
		//-----------------------------
		// variables
		//-----------------------------
		
		/** 无匠背景 */
		public var bgRect:Scale3Image;
		/** 加匠背景 */
		public var selectedBg:Scale3Image;
		/** 颜色组 */
		public var sharpColorGroup:Sprite;
		
		//-----------------------------
		// properties
		//-----------------------------
		
		//-----------------------------
		// setter&getter
		//-----------------------------
		
		//-----------------------------
		// methods
		//-----------------------------
		
		/**
		 * 初始化函数 
		 * 
		 */		
		public function initialize():void
		{
			bgRect = FG2FUGenerator.drawRoundRectImage2(
				UISize.SHARP_CON_BG_H, 
				Color.WHITE, UISize.DPI_SCALE, 12, "default"
			);
			
			bgRect.width = UISize.SHARP_CON_BG_W * UISize.DPI_SCALE;
			bgRect.height = UISize.SHARP_CON_BG_H * UISize.DPI_SCALE;
			this.addChild( bgRect );
			
			selectedBg = FG2FUGenerator.drawRoundRectImage2(
				UISize.SHARP_CON_BG_H, 
				ColorLib.ORANGE, UISize.DPI_SCALE, 12, "default"
			);
			
			selectedBg.width = UISize.SHARP_CON_BG_W * UISize.DPI_SCALE;
			selectedBg.height = UISize.SHARP_CON_BG_H * UISize.DPI_SCALE;
			selectedBg.visible = false;
			this.addChild( selectedBg );
			
			sharpColorGroup = new Sprite();
			sharpColorGroup.x = sharpColorGroup.y = UISize.SHARP_CON_PADDING * 
				UISize.DPI_SCALE;
			this.addChild( sharpColorGroup );
		}
		
		/**
		 * 设置斩味数据 
		 * @param sharpArr 武器数据
		 * @param isAdd 是否匠后
		 * 
		 */		
		public function setSharpData( sharpArr:Array, isAdd:Boolean ):void
		{
			var perW:Number = ( UISize.SHARP_CON_BG_W - UISize.SHARP_CON_PADDING * 2 ) / 40 *
				UISize.DPI_SCALE;
			var quadH:Number = ( UISize.SHARP_CON_BG_H - UISize.SHARP_CON_PADDING * 2 ) *
				UISize.DPI_SCALE;
			var totalCount:int = 0;
			var colorArr:Array = [
				ColorLib.REDS, ColorLib.ORANGES, ColorLib.YELLOWS,
				ColorLib.GREENS, ColorLib.BLUES, 0xFFFFFF,
				ColorLib.PURPLES
			];
			var len:int = colorArr.length;
			
			sharpColorGroup.removeChildren( 0, sharpColorGroup.numChildren, true );
			
			for ( var i:int = 0; i < len; i ++ )
			{
				var quad:Quad = new Quad( perW * sharpArr[ i ], quadH, colorArr[ i ] );
				
				quad.x = totalCount * perW;
				sharpColorGroup.addChild( quad );
				totalCount += sharpArr[ i ];
			}
			
			bgRect.visible = !isAdd;
			selectedBg.visible = isAdd;
		}
		
		//-----------------------------
		// events
		//-----------------------------
		
		//-----------------------------
		// dispose
		//-----------------------------
		
		/**
		 * 析构函数 
		 * 
		 */		
		override public function dispose():void
		{
			bgRect.dispose();
			FG2FUGenerator.deepDisposeScale3Image( bgRect );
			bgRect = null;
			
			selectedBg.dispose();
			FG2FUGenerator.deepDisposeScale3Image( selectedBg );
			selectedBg = null;
			
			sharpColorGroup.removeChildren( 0, sharpColorGroup.numChildren, true );
			sharpColorGroup.dispose();
			sharpColorGroup = null;
		}
		
		//-----------------------------
		// construction
		//-----------------------------
		
		/**
		 * 构造函数
		 *
		 */
		public function SharpContainer()
		{
			super();
			initialize();
		}
	}
}